import React from 'react';
import {Form, Select} from "antd";
import {DefaultOptionType} from "rc-select/lib/Select";
import {OutboundDeliveryOrder} from "type/OutboundDeliveryOrder";

import {OdoTypeSelectProps} from "../../../init";
import useAsyncEffect from "../../../../../hooks/useAsyncEffect";
import {getEngineOptions} from "../../../SeleteOptionHanlder";
import DrpSettingHandler from "../../../DrpSettingHandler";

const ServiceOdoSelect = ({form}: OdoTypeSelectProps) => {
    const [loading,setLoading] = React.useState<boolean>(true) ;
    const [options,setOptions] = React.useState<DefaultOptionType[]>([]) ;
    useAsyncEffect( async () => {
        setOptions(await getEngineOptions()) ;
        form.setFieldValue("odoFlow",DrpSettingHandler.getInstance().getConfig().defaultEngine) ;
        setLoading(false) ;
    });
    return (
        <Form.Item<OutboundDeliveryOrder> label={"服务发动机编号"} name={"odoFlow"} required>
            <Select loading={loading} options={options}/>
        </Form.Item>
    );
};

export default ServiceOdoSelect;